/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-04-22
 * Time: 22:36
 */

import java.io.*;
import java.util.Scanner;

/**
 * 将一个文件内容复制到另一个文件中
 */
public class Demo2 {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要复制的文件路径");
        String srcPath  = scanner.next();

        System.out.println("请输入到复制到的文件路径");
        String destPath = scanner.next();
        File f1 = new File(srcPath);
        if(!f1.isFile()){
            System.out.println("输入错误");
            return;
        }
        File f2 = new File(destPath);;
        if(!f2.getParentFile().isDirectory()){
            return;
        }

        try(InputStream inputStream = new FileInputStream(f1);
            OutputStream outputStream = new FileOutputStream(f2)){
            while(true){
                byte[] bytes = new byte[1024];
                int n = inputStream.read(bytes);
                if(n==-1){
                    break;

                }
                outputStream.write(bytes,0,n);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
